package com.qf.j2102.controller;

import com.qf.j2102.common.JsonBean;
import com.qf.j2102.po.SysCar;
import com.qf.j2102.service.SysCarService;
import com.qf.j2102.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/car")
public class SysCarController {

    @Autowired
    private SysCarService carService;

    @RequestMapping("/price.do")
    @ResponseBody
    public JsonBean selectByPrice(Integer getid) {
        JsonBean bean = null;

        try {
            List<SysCar> list = carService.findByprice(getid);
            bean = JsonUtils.createJsonBean(1, list);

        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0, e.getMessage());
        }

        return bean;

    }

    @RequestMapping("/number.do")
    @ResponseBody
    public JsonBean selectByNumber(Integer getid) {
        JsonBean bean = null;
        try {
            List<SysCar> list = carService.findByNum(getid);
            bean = JsonUtils.createJsonBean(1,list);
        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0,e.getMessage());
        }
        return bean;

    }


    @RequestMapping("/findcar.do")
    @ResponseBody
    public JsonBean findCar(Integer cid) {
        JsonBean bean = null;
        try {
            SysCar car = carService.findById(cid);
            bean = JsonUtils.createJsonBean(1,car);


        }catch (Exception e) {
            bean = JsonUtils.createJsonBean(0,e.getMessage());
        }
        return bean;
    }


}
